// run: $exec < input
// f[1] = 0
// f[i] = (f[i - 1] + m) % i
#include <iostream>
#include <vector>
#include <set>

int const maxn = 250;
std::set<int> f[maxn];
std::vector<int> a;
int n, m;

int main()
{
	std::ios::sync_with_stdio(false);
	int T; std::cin >> T;
	while (T--) {
		std::cin >> n >> m;
		for (int i = 0; i <= n; i++) f[i].clear();
		a.clear(); a.resize(m);
		for (int i = 0; i < m; i++) std::cin >> a[i];
		f[1].insert(0);
		for (int i = 2; i <= n; i++) {
			for (auto t : f[i - 1]) {
				for (auto tm : a) {
					int tmp = (t + tm) % i;
					f[i].insert(tmp);
				}
			}
		}
		std::cout << f[n].size() << "\n";
		bool first = true;
		for (auto i : f[n]) {
			if (!first) std::cout << " ";
			else first = false;
			std::cout << i + 1;
		}
		std::cout << "\n";
	}
}

